<?php

/*
 * This file is part of the Geek-Zoo Projects.
 *
 * @copyright (c) 2010 Geek-Zoo Projects More info http://www.geek-zoo.com
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License
 * @author quqiang <quqiang@geek-zoo.com>
 *
 */

require ROOT_PATH.'/Helper/front_abstract.php';

class Action extends front_abstract
{
    
    function index()
    {
        
    }
    
    function create()
    {
	  if (empty($this->info)) {

            	$this->info['id'] = 0;
	  
	  }
        $type = _GET('type', 0);
        $post_id = _GET('post_id', 0);
        $user_id = $this->info['id'];
        if (!$type || !$post_id) {
	    
		die("参数错误");
        }


	if(!$user_id){
		$check1 = explode(',', $_COOKIE['q']);//do
		$check2 = explode(',', $_COOKIE['z']);//do


		if(in_array($post_id, $check1)){
			die("重复评价是无聊的行为，而且一点也不危险");
		}

		if(in_array($post_id, $check2)){
			die("重复评价是无聊的行为，而且一点也不危险");
		}

		if($type == 1){
			$check1[] = $post_id;
			setcookie('q', implode(',', $check1), time()+3600*24*30);
		}

		if($type == 2){
			$check2[] = $post_id;
			
			setcookie('z', implode(',', $check2), time()+3600*24*30);
		}

	} else {
	
		if ($type != 3) {
            		$check1 = _model('favor')->read(array('user_id'=>$user_id, 'post_id'=>$post_id, 'type'=>1));
            		$check2 = _model('favor')->read(array('user_id'=>$user_id, 'post_id'=>$post_id, 'type'=>2));
           	 	
			if ($check1) {
                		die('重复评价是无聊的行为，而且一点也不危险');
            		}
           		 if ($check2) {
                		die('重复评价是无聊的行为，而且一点也不危险');
            		}
       		 }
	
	}

        

        $id = _model('favor')->create(array('post_id'=>$post_id, 'type'=>$type, 'user_id'=>$user_id, 'add_time'=>time()));
        
        $count = _model('favor')->getCount(array('post_id'=>$post_id, 'type'=>$type));
        switch ($type) {
            case '1':
                _model('post')->update(array('id'=>$post_id), array('kiss_num'=>$count));
                break;
            case '2':
                _model('post')->update(array('id'=>$post_id), array('palm_num'=>$count));
                break;
            case '3':
                _model('post')->update(array('id'=>$post_id), array('favor_num'=>$count));
                break;
	}
		$post_info = _model('post')->read(array('id'=>$post_id));

	if ($id) {
			if($type==1){
			
				_model('post')->update(array('id'=>$post_id), array('hotcolor_num'=>$post_info['hotcolor_num']+1));
				die("嚯~~~");
			
			}else{
				_model('post')->update(array('id'=>$post_id), array('hotcolor_num'=>$post_info['hotcolor_num']-1));
				die("你能更危险么?");
			}
        }else {
            die("失败");
        }
    }
}

?>
